import {createStore} from 'vuex'
import router from "@/router/index.js";
// 创建一个新的 store 实例
const store = createStore({
    state() {
        return {
            tabList: [],
        }
    },
    mutations: {
        addTab: (state, tab) => {
            if (state.tabList.some(item => item.path === tab.path))
                return
            state.tabList.push(tab)
            console.log(state.tabList)
        },
        delete_tabs(state, route) {
            console.log(route)
            let index = 0
            for (let list of state.tabList) {
                if (list.path === route) {
                    break
                }
                index++
            }
            this.state.tabList.splice(index, 1)
            if (state.tabList.length > 0) {
                router.push(state.tabList.at(state.tabList.length - 1))
            }
        }
    }
})

export default store